package com.mint.foo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by larry on 2016/10/09.
 * description
 */
@RestController
public class FooController {

    @Autowired
    private DiscoveryClient client;

    @RequestMapping(value = "/message", method = RequestMethod.GET)
    public String index(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {

        String s = String.format("foo->method:%1$s id:%2$s port:%3$s time:%4$s",
                httpServletRequest.getMethod(),
                this.client.getLocalServiceInstance().getServiceId(),
                this.client.getLocalServiceInstance().getPort(),
                System.currentTimeMillis());

        return s;
    }
}
